package com.lanyan.system.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;

import com.lanyan.system.service.IAccountService;
import com.lanyan.system.service.ICourierService;
import com.lanyan.system.service.IProductService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.lanyan.system.domain.Evaluate;
import com.lanyan.system.service.IEvaluateService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 评价Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/evaluate")
public class EvaluateController extends BaseController
{
    @Autowired
    private IEvaluateService evaluateService;
    @Autowired
    private IAccountService accountService;
    @Autowired
    private ICourierService courierService;
    @Autowired
    private IProductService productService;

    /**
     * 查询评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "courierId", value = "所属配送员", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "speed", value = "速度评分", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "manner", value = "服务评分/商品评价", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "distribution", value = "配送评分/描述相符", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "content", value = "评价内容", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "image", value = "图片", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
          @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    public TableDataInfo list(Evaluate evaluate)
    {
        startPage();
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        for (Evaluate item : list) {
            item.setAccount(accountService.getById(item.getAccountId()));
            item.setCourier(courierService.getById(item.getCourierId()));
            item.setProduct(productService.getById(item.getProductId()));
        }
        return getDataTable(list);
    }

    /**
     * 导出评价列表
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:export')")
    @Log(title = "评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Evaluate evaluate)
    {
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        ExcelUtil<Evaluate> util = new ExcelUtil<Evaluate>(Evaluate.class);
        util.exportExcel(response, list, "评价数据");
    }

    /**
     * 获取评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:query')")
    @GetMapping(value = "/{evaluateId}")
    public AjaxResult getInfo(@PathVariable("evaluateId") Long evaluateId)
    {
        return success(evaluateService.selectEvaluateByEvaluateId(evaluateId));
    }

    /**
     * 新增评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:add')")
    @Log(title = "评价", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "courierId", value = "所属配送员", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "speed", value = "速度评分", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "manner", value = "服务评分/商品评价", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "distribution", value = "配送评分/描述相符", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "content", value = "评价内容", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "image", value = "图片", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody Evaluate evaluate)
    {
        return toAjax(evaluateService.insertEvaluate(evaluate));
    }

    /**
     * 修改评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:edit')")
    @Log(title = "评价", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "accountId", value = "所属用户", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "courierId", value = "所属配送员", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "speed", value = "速度评分", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "manner", value = "服务评分/商品评价", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "distribution", value = "配送评分/描述相符", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "content", value = "评价内容", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "image", value = "图片", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody Evaluate evaluate)
    {
        return toAjax(evaluateService.updateEvaluate(evaluate));
    }

    /**
     * 删除评价
     */
    @PreAuthorize("@ss.hasPermi('system:evaluate:remove')")
    @Log(title = "评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{evaluateIds}")
    public AjaxResult remove(@PathVariable Long[] evaluateIds)
    {
        return toAjax(evaluateService.deleteEvaluateByEvaluateIds(evaluateIds));
    }
}
